﻿<?php
ini_set('date.timezone','Asia/Shanghai');
include 'simple_html_dom.php';
include 'config_catchanzhi.php';

define('APPS_NUM',2405);
define('GAMES_NUM',977);

define('DBPAS',"coolchuan2012");
//define('DBPAS',"123456");

$link = mysql_connect("localhost","root",DBPAS); 
//$link = mysql_connect("localhost","root","coolchuan2012"); 
mysql_select_db("catchappdataall", $link);
mysql_query('SET NAMES UTF8');






		$app_info_insertdb_arr = get_exit_appinfo_fromdb();
		
foreach ($app_info_insertdb_arr as $app_info_insertdb)
{
	
	$packagename = $app_info_insertdb['packageName'];


		while (1)
		{
			if(strpos($packagename, "/") === false)
			{
				break;
			}
			$pos = strpos($packagename, "/")+1;
			//if($pos == "")
			$packagename = substr($packagename,$pos,(strlen($packagename)-$pos));
		}
		
		
		
		$pos = strpos($packagename, "_");
		
		
		if($pos != "")
		{
			$packagename = substr($packagename,0,$pos);
		}
		$app_info_insertdb['packageName'] = $packagename;

		insert_appinfo_ifnotexit_todb($app_info_insertdb);
}
		

		
		
function get_exit_appinfo_fromdb()
{
	$link = mysql_connect("localhost","root",DBPAS); 
	$createtime = strtotime(date("Y-m-d H:i:s"));

	$sql = 'select id,  packageName,title from jk_apps_info_anzhi where IsDeleted=0 '; 
	$rs = mysql_query($sql, $link);
	
	$app_exit_info = array();
  	while($row=mysql_fetch_array($rs))        
  	{
  		$app_exit_info_temp = array();
  		$app_exit_info_temp['id'] = $row['id'];
	  	$app_exit_info_temp['packageName'] = $row['packageName'];
	  	$app_exit_info[] = $app_exit_info_temp;
  	}
	return $app_exit_info;
}

//app基础信息
function insert_appinfo_ifnotexit_todb($app_info)
{
	$link = mysql_connect("localhost","root",DBPAS); 
	$createtime = strtotime(date("Y-m-d H:i:s"));

	$sql = 'update jk_apps_info_anzhi set packageName = "'.$app_info['packageName'].'" where id = '.$app_info['id'].''; 

	$rs = mysql_query($sql, $link);
	
}





?>